<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img{
            display: block;
            margin: 5% auto;
        }
    </style>
</head>
<body>
    <img width="500" src="./images/kitteh1.jpg" alt="">


    <script>
        const img=document.querySelector('img')
        img.addEventListener('mousemove',function(ev){
            const io =  {x:this.offsetWidth/2, y:this.offsetHeight/2}
            const pp = {x:ev.offsetX, y:ev.offsetY}
            const disX = pp.x-io.x
            const disY = pp.y-io.y
            const pd = Math.sqrt(disX*disX + disY*disY)
            const maxD=Math.sqrt(io.x*io.x + io.y*io.y)
            const d = (pd/maxD)/4
            const x = Math.atan(Math.abs(disY)/Math.abs(disX))
            let degX = x/Math.PI*180*d
            const y = Math.atan(Math.abs(disX)/Math.abs(disY))
            let degY = y/Math.PI*180*d
            
            if(disX >= 0 && disY < 0){
            }else if(disX >= 0 && disY >= 0){
                degX = 0-degX
            }else if(disX < 0 && disY >= 0){
                degX = 0-degX
                degY = 0-degY
            }else if(disX < 0 && disY < 0){
                degY = 0-degY
            }
            this.style.transform=`perspective(3000px) rotateX(${degX}deg) rotateY(${degY}deg)`
        })
        img.addEventListener('mouseout',function(){
            this.style.transform=`perspective(3000px) rotateX(0deg) rotateY(0deg)`
        })
    </script>
</body>
</html>